package com.codinghero.example.daily;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ListFiles {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		File folder = new File("E:\\private\\足球导航站\\图片\\soccer_gf");
		String DOMAIN = "http://zuqiulaba-image.stor.sinaapp.com/";
		String IMG_URI = DOMAIN + "soccer/gf/";
		String THUMB_URI = IMG_URI + "thumbs/";
		File[] files = folder.listFiles();
		System.out.println("<div style=\"height:120px \">");
		for (int i = 0, num = 0; i < files.length; i++, num++) {
			if (files[i].isDirectory()) {
				num--;
				continue;
			}
			String fileName = files[i].getName();
			int dotIndex = files[i].getName().lastIndexOf(".");
			String thumbName = files[i].getName().substring(0, dotIndex)
					+ ".jpg";
			BufferedImage img = ImageIO.read(files[i]);
			if (i > 0 && i % 8 == 0) {
				System.out.println("</div>");
				System.out.println("<div style=\"height:120px \">");
			}
			if (fileName.endsWith("jpg")
					|| fileName.endsWith("jpeg")
					|| fileName.endsWith("bmp")
					|| fileName.endsWith("png")
					|| fileName.endsWith("gif")) {
				String imageUrl = IMG_URI + fileName;
				String thumbUrl = THUMB_URI + thumbName;
				System.out.println("\t<span>");
				System.out.println("\t\t<a href=\"" + imageUrl + "\" target=\"_blank\" >");
				if (img.getWidth() > img.getHeight()) {
					System.out.println("\t\t\t<img class=\"article user-picture\" src=\""+ thumbUrl + "\" style=\"width:100px;height:75px\" />");
				} else {
					System.out.println("\t\t\t<img class=\"article user-picture\" src=\""+ thumbUrl + "\" style=\"width:75px;height:100px\" />");
				}
				
				System.out.println("\t\t</a>");
				System.out.println("\t</span>");
			}
		}
		System.out.println("</div>");
	}

}
